﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using BLL.CustomAttribute;
using BLL.Enum;
using BLL.Model.OperatingSystem;
using BLL.Model.User;
using BLL.Utility;
using DataAnnotationsExtensions;

namespace BLL.Model.Apply
{
    public class ApplyInfo
    {
        public ApplyInfo()
        {
            ApplyDate = DateTime.Now;
            CurrentStatus = ApplyProcessStatus.Wait;
        }

        [Key, StringProperty]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }

        [Display(Name = "标题"), StringLength(300), StringProperty]
        [Required(AllowEmptyStrings = false)]
        public string Title { get; set; }

        [Display(Name = "内存(MB)"), StringProperty]
        [Required, Integer(ErrorMessage = "内存大小必须是个整数")]
        public int? MemroySize { get; set; }

        [Display(Name = "存储(GB)"), StringProperty]
        [Required, Integer(ErrorMessage = "存储大小必须是个整数")]
        public int? DiskSize { get; set; }

        [Display(Name = "CPU(Core)"), StringProperty]
        [Required, Integer(ErrorMessage = "CPU个数必须是个整数")]
        public int? CPUCore { get; set; }

        [Display(Name = "备注"), StringLength(500), StringProperty]
        public string Comment { get; set; }

        [Display(Name = "申请日期"), Required, StringProperty]
        public DateTime ApplyDate { get; set; }

        [Required]
        public int CurrentStatusValue { get; set; }

        [NotMapped, Display(Name = "最新审批状态")]
        public ApplyProcessStatus CurrentStatus
        {
            get { return (ApplyProcessStatus)CurrentStatusValue; }
            set { CurrentStatusValue = (int)value; }
        }

        [Required]
        public int ApplyUserId { get; set; }

        [Display(Name = "申请人"), ForeignKey("ApplyUserId")]
        public virtual UserInfo ApplyUser { get; set; }

        public virtual IList<ApplyProcess> Process { get; set; }

        public int? OperatingSystemId { get; set; }

        [ForeignKey("OperatingSystemId")]
        public virtual OperatingSystemInfo OperatingSystemType { get; set; }

        public override string ToString()
        {
            return ModelHelper<ApplyInfo>.AutoCreateModelString(this);
        }

    }
}